/**
 * @param {number} n
 * @return {number}
 */
var tribonacci = function(n) {
    let T0 = 0,T1 = 1,T2 = 1,res
    for(let i = 3; i < n + 1; i++){
        res = T0 + T1 + T2
        T0 = T1
        T1 = T2
        T2 = res
    }
    if(n === 0){
        res = 0
    }else if(n === 1 || n === 2){
        res = 1
    }
    return res
};